export default function (id, data, viewList, viewMap) {
    let loginPath = data.loginPath;
    let toRegisterPath = data.toRegisterPath;
    let idStr = id.toString();
    let clientId = '';
    let types = '';
    // dynamicLoadCss("/Direct/com.nebutown.workflow.root.Root/commonui/commoncss/layui.css")
    // dynamicLoadJs("/Direct/com.nebutown.workflow.root.Root/commonui/commonjs/layui.all.js")
    // dynamicLoadJs("https://unpkg.com/qiniu-js@2.5.4/dist/qiniu.min.js")
    window.nbasics.loadingCss("https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css")
    let style = `
                <style>
                     .centerLogin{
                    width: 60%;
                    height: 50%;
                    position: fixed;
                    margin: auto;
                    top: 0;
                    left: 0;
                    bottom: 0;
                    right: 0;
                  }
                  .centerLogin h1{
                    text-align: center;
                  }
                  label{
                  font-size: 12px;
                  }
                  .toRegisterBtn{
                    float: right;
                    font-size: 12px;
                    margin-top: 15px;
                  }
                </style>
    `
    let html = `
                <div class="centerLogin jumbotron" style="background: white">
                    <h1>用户登录</h1>
                     <div class="form-group">
                        <label>账户名</label>
                        <input type="text" class="form-control userName" id="exampleInputEmail1" placeholder="Username" autofocus autocomplete="off">
                      </div>
                      <div class="form-group">
                        <label for="exampleInputPassword1">密码</label>
                        <input type="password" class="form-control password" id="exampleInputPassword1" placeholder="Password">
                      </div>
                      <button type="button" class="btn btn-primary loginBtn" style="width: 100%;margin-top: 20px">登录</button>
                      <span class="toRegisterBtn">注册</span>
                      <!--<span class="phoneCall">打电话</span>-->
                </div>
                `;
    let warningStr = `<div class="warnWindow"><div>${data.message ? data.message : ''}</div><span class="forSure">确定</span></div>`
    if (data.message) {
        html += warningStr;
    }
    // let headerString = header({'title':'登录'});
    // let searchString = search({'valueList':[1,2,3,4,5,6]});
    // let exampleString = example({});
    // html =  headerString + html;
    // html = exampleString;
    window.nbasics.differAction(() => {
        var plusReady = function (callback) {
            if (window.plus) {
                callback();
            } else {
                document.addEventListener('plusready', callback);
            }
        };

    plusReady(function () {
        let currentWebview = plus.webview.currentWebview();
        let topWebview = plus.webview.getTopWebview();
        let pinf = plus.push.getClientInfo();
        plus.push.addEventListener('receive', function (msg) {
            //处理透传消息的业务逻辑代码
            plus.push.createMessage("测试消息", "LocalMSG", {cover: false, sound: "system"});
        }, false);
        clientId = pinf.clientid;//客户端标识
        var firstBack = 0;
        var handleBack = function () {
            var now = Date.now || function () {
                return new Date().getTime();
            };

            currentWebview.canBack(function (evt) {
                /**
                 * 有可后退的历史记录，则后退。
                 * 否则，关闭当前窗口。
                 * 如果当前窗口是入口页，那么执行退出的逻辑。
                 */
                if (currentWebview.id !== plus.runtime.appid) {
                    if (!firstBack) {
                        firstBack = now();
                        plus.nativeUI.toast('再按一次退出应用');

                        setTimeout(function () {
                            firstBack = 0;
                        }, 2000);
                    } else if (now() - firstBack < 2000) {
                        plus.runtime.quit();
                    }
                } else {
                    if (evt.canBack) {
                        history.back();
                    } else {
                        currentWebview.close('auto');
                    }
                }
            });
        };

        plus.key.addEventListener('backbutton', handleBack);
    });
    if (/(iPhone|iPad|iPod|iOS|Android)/i.test(navigator.userAgent)) { //移动端
        types = 'mobile'
    } else {
        types = 'pc'
    }
    console.log(types)
    // window.nbasics.touchBack({"path": loginPath, data: JSON.stringify({"userName": 'admin', "password": 'root'})})
    let parentNode = document.getElementById(idStr);
    let loginBtn = parentNode.querySelector(".loginBtn");
    let toRegisterBtn = parentNode.querySelector(".toRegisterBtn");
    let userName = parentNode.querySelector(".userName");
    let password = parentNode.querySelector(".password");
    let forSure = parentNode.querySelector(".forSure");
    if (forSure) {
        forSure.onclick = function () {
            document.querySelector('.warnWindow').style.display = 'none';
        }
    }
    // let phoneCall =document.querySelector('.phoneCall');
    // phoneCall.onclick = () => {
    //     plus.device.dial( "10086", false );
    // }
    document.getElementById(id).onkeydown = function (e) {
        var ev = document.all ? window.event : e;
        if (ev.keyCode === 13) {
            let dataObjCollector = {
                "userName": userName.value,
                "password": password.value,
                "clientId": clientId,
                "clientType": types
            };
            window.nbasics.touchBack({"path": loginPath, data: JSON.stringify(dataObjCollector)})
        }
    }
    loginBtn.onclick = function () {
        let dataObjCollector = {
            "userName": userName.value,
            "password": password.value,
            "clientId": clientId,
            "clientType": types
        };
        window.nbasics.touchBack({"path": loginPath, data: JSON.stringify(dataObjCollector)})
    }
    toRegisterBtn.onclick = function () {
        let dataObjCollector = {};
        window.nbasics.touchBack({"path": toRegisterPath, data: JSON.stringify(dataObjCollector)})
    }
    window.canPost = function () {
        if (userName.value && password.value) {
            loginBtn.className = 'loginBtn'
        } else {
            loginBtn.className = 'loginBtn unuseloginBtn'
        }
    }
})
    ;
    return (`<div id="${id}">${style}${html}</div>`);
}